package reflect;

import java.lang.reflect.Field;

public class ReflectDemo10 {
    public static void main(String[] args) throws Exception{
        Class cls=Class.forName("reflect.Teacher");
        Object obj=cls.newInstance();
        Field field=cls.getField("name");
        field.set(obj,"张三");
        Field field1=cls.getField("age");
        field1.set(obj,18);
        System.out.println(obj);
        //获取属性值
        Object v=field.get(obj);
        System.out.println(v);
        Object q=field1.get(obj);
        System.out.println(q);
    }
}
